package com.finance.system.configure.websecurity;

import com.finance.system.support.bean.GlobalResponse;
import com.finance.system.support.utils.JSONUtils;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class FinanceAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response,
                       AccessDeniedException e) throws IOException, ServletException {
        GlobalResponse<Object> fail = GlobalResponse.fail(e.getMessage(), null);
        response.getWriter().println(JSONUtils.obj2json(fail));
    }
}
